package com.movie.ticketing.schedule.service;

import com.movie.ticketing.schedule.entity.Schedule;
import com.movie.ticketing.schedule.repository.ScheduleRepository;
import com.movie.ticketing.schedule.repository.HallRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScheduleService {
    @Autowired
    private ScheduleRepository scheduleRepository;

    @Autowired
    private HallRepository hallRepository;

    public List<Schedule> getAllSchedules() {
        return scheduleRepository.getAllSchedules();
    }

    public Schedule getScheduleById(Long id) {
        return scheduleRepository.getScheduleById(id);
    }

    public Schedule saveSchedule(Schedule schedule) {
        // 确保影厅存在
        if (hallRepository.getHallById(schedule.getHallId().longValue()) == null) { // 进行类型转换
            throw new IllegalArgumentException("影厅不存在");
        }
        return scheduleRepository.saveSchedule(schedule);
    }

    public Schedule updateSchedule(Long id, Schedule scheduleDetails) {
        // 确保影厅存在
        if (hallRepository.getHallById(scheduleDetails.getHallId().longValue()) == null) { // 进行类型转换
            throw new IllegalArgumentException("影厅不存在");
        }
        return scheduleRepository.updateSchedule(id, scheduleDetails);
    }

    public void deleteSchedule(Long id) {
        scheduleRepository.deleteSchedule(id);
    }
}